/**
 * 测试client
 **/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <errno.h>
#include "../src/lib/zipmap.h"
#include "../src/client.h"

int main(int argc, char* argv[])
{
    if (argc < 3 || argc > 4) {
        printf("usage: %s method url [data]\n", argv[0]);
        exit(1);
    }

    http_entity_t *http = client_request_ex(argv[1], argv[2], NULL, (argc == 4) ? argv[3] : NULL);

    if (http == NULL) {
        printf("<nil>\n");
    } else {
        zipReset(http->headers);
        char *key, *value;
        while (zipNext(http->headers, &key, &value)) {
            printf("%s: %s\r\n", key, value);
        }
        printf("\r\n");
        printf("%s\n", http->body);
    }

    return 0;
}
